<?php

use Phalcon\Forms\Element\Email,
    Phalcon\Forms\Element\Text,
    Phalcon\Forms\Element\Hidden,
    Phalcon\Forms\Element\Password,
    Phalcon\Forms\Element\Check,
    Phalcon\Forms\Element\Submit,
    Phalcon\Validation\Validator\PresenceOf,
    Phalcon\Validation\Validator\Confirmation,
    Phalcon\Validation\Validator\Email As EmailValidate,
    Phalcon\Validation\Validator\Identical,
    Phalcon\Validation\Validator\StringLength;

/**
 * validate and print render Frontend login form
 */
class RegisterForm extends BaseForm {

    public function initialize() {
        
        // Email
        $email = new Email('email', array(
            'placeholder' => 'Email Address',
            'required' => true,
            'type' => 'email',
        ));
        $email->addValidators(array(
            new PresenceOf(array(
                'message' => 'Email is required!'
                    )),
            new EmailValidate(array(
                'message' => 'Email is not valid!'
                    )),
        ));
        $this->add($email);

        //Password
        $password = new Password('password', array(
            'placeholder' => 'Password',
            'min-length' => 6,
            'max-length' => 50,
            'required' => true,
        ));
        $password->addValidators(array(
            new PresenceOf(array(
                'message' => 'Password is required!'
                    )),
            new StringLength(array(
                'max' => 50,
                'min' => 6,
                'messageMaximum' => 'Password must be maximum 50 characters!',
                'messageMinimum' => 'Password must be minimum 6 characters!'
                    )),
        ));
        $this->add($password);
        
        //Password
        $passwordConfirm = new Password('password-confirm', array(
            'placeholder' => 'Confirm password',
            'min-length' => 6,
            'max-length' => 50,
            'required' => true,
        ));
        $passwordConfirm->addValidators(array(
            new PresenceOf(array(
                'message' => 'Password is required!'
                    )),
            new StringLength(array(
                'max' => 50,
                'min' => 6,
                'messageMaximum' => 'Password must be maximum 50 characters!',
                'messageMinimum' => 'Password must be minimum 6 characters!'
                    )),
            new Confirmation(array(
                'message' => 'Confirm passwod is not valid',
                'with' => 'password'
                    ))
        ));
        $this->add($passwordConfirm);
        
        // Full Name
        $name = new Text('name', array(
            'placeholder' => 'Full Name',
            'required' => true,
        ));
        $name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Name is required!'
                    ))
        ));
        $this->add($name);

        //Term
        $term = new Check('term');
        $term->addValidator(new PresenceOf(array(
                'message' => 'You must agree with our term!'
                    )));
        $term->setLabel('Remember me');
        $this->add($term);

        //CSRF
        $csrf = new Hidden('csrf');
        $csrf->addValidator(
                new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
                ))
        );
        $this->add($csrf);
        
        // Submit button
        $this->add(new Submit('submit', array(
            'class' => 'btn btn-primary btn-large'
        )));
    }

}
